package com.leslie.hhcommunity.event;

import com.alibaba.fastjson.JSONObject;
import com.leslie.hhcommunity.entity.Event;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
 * @author
 * @PackageName:com.leslie.hhcommunity.event
 * @ClassnName:EventProducer
 * @Description: 事件生产者
 * @Date 2022/1/7  21:18
 */
@Component
public class EventProducer {

	@Autowired
	KafkaTemplate kafkaTemplate;

	/**
	 * 处理事件
	 * @param event
	 */
	public void fireEvent(Event event){
		//将事件发布到指定主题, event对象转成json之后的字符串
		kafkaTemplate.send(event.getTopic(), JSONObject.toJSONString(event));
	}
}
